﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Test_2D
{
    partial class EditForm //Form1
    {
        //PictureBox cur_picbox;
        //bool dragging = false;
        //int mouse_x, mouse_y;       //获取鼠标单击时的鼠标坐标
        //Graphics g;
/*
        private void newPicbox(Motion _mot)
        {
            PictureBox newpicbox = new PictureBox();
            newpicbox.BackColor = Color.White;
            newpicbox.BackgroundImageLayout = ImageLayout.Stretch;
            //newpicbox.BorderStyle = BorderStyle.FixedSingle;

            newpicbox.Size = _mot.Size;
            newpicbox.BackgroundImage = _mot.Image;
            newpicbox.Tag = _mot;
            newpicbox.Location = _mot.Location;

            //newpicbox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseMove);
            //newpicbox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDown);
            //newpicbox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseUp);

            
            this.panel2.Controls.Add(newpicbox);
            pickBox.WireControl(newpicbox);
            picboxs.Add(newpicbox);
            //newpicbox.BringToFront();
            

            //cur_picbox = newpicbox;
        }

        //给PictureBox画边框
        private void picBorder(bool select, PictureBox picbox)
        {
            g = picbox.CreateGraphics();

            Pen pen;
            if (select == false)
                pen = new Pen(picbox.BackColor);
            else
                pen = new Pen(Color.Red);

            g.DrawRectangle(pen, 0, 0, picbox.Width - 1, picbox.Height - 1);
        }

        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            dragging = true;

            mouse_x = e.X;    //获取鼠标在pictruebox的位置
            mouse_y = e.Y;

            if (cur_picbox == null)
                cur_picbox = (PictureBox)sender;
            else if (cur_picbox.Equals((PictureBox)sender))
                return;     //选取的就是上一个选取的对象

            //picBorder(false, cur_picbox);
            //cur_picbox.BorderStyle = BorderStyle.None;
            cur_picbox = (PictureBox)sender;
            cur_picbox.BringToFront();
            //cur_picbox.BorderStyle = BorderStyle.FixedSingle;
            //picBorder(true, cur_picbox); 
            cur_picbox.Capture = true;
        }

        private void pictureBox_MouseMove(object sender, MouseEventArgs e)  //e.X是鼠标相对picbox的坐标
        {
            if (dragging)
            {
                cur_picbox.Left = cur_picbox.Left - mouse_x + e.X;
                cur_picbox.Top = cur_picbox.Top - mouse_y + e.Y;
                //label1.Text = tmp_x + " | " + e.X + " | " + tmp.Top + " | " + tmp.Left;
            }
        }

        private void pictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            newLocation();
            dragging = false;
        }
        */

    }
}

